/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.jSkyRoom.example;

import java.io.IOException;
import java.util.Collection;
import ru.jSkyRoom.finder.FinderByEdidFacade;
import ru.jSkyRoom.interfaces.JSkyMod;
import ru.jSkyRoom.interfaces.major.NPC;
import ru.jSkyRoom.interfaces.major.Spell;
import ru.jSkyRoom.manager.JSkyGlobal;
import ru.jSkyRoom.manager.ModManager;
import ru.jSkyRoom.selector.SelectorFacade;
import ru.jSkyRoom.support.GrupTypeBuilder;
import skyproc.GRUP_TYPE;
import skyproc.exceptions.BadMod;
import skyproc.exceptions.BadRecord;
import skyproc.exceptions.MissingMaster;

/**
 *
 * @author Rakev
 */
public class FireballForAllExample {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws BadMod, MissingMaster, IOException, BadRecord {
        FireballForAllExample app = new FireballForAllExample();
        app.apply();
    }

    private void apply() throws BadMod, MissingMaster, IOException, BadRecord {
        init();
        execute();
        save();
    }

    private void init() throws BadMod, MissingMaster {
        String pathToData = "C:\\Steam\\SteamApps\\common\\skyrim\\Data\\";
        String author = "Rakev";
        String patchName = "FireballForAllExample";
        String importingMod1 = "Skyrim.esm";
        String importingMod2 = "Update.esm";
        //Selecting used GrupTypes: NPC, Spell
        GRUP_TYPE[] grupTypes = new GrupTypeBuilder().NPC().Spell().build();

        //init creating Mod
        JSkyGlobal.getInstance().begin().
                selectActiveMode(pathToData). //Set the path to the directory with the mods and transition to phase selection edited mod
                beginCreatingMod(author, patchName). //Choose to create a new mod
                importMod(importingMod1, grupTypes). //Import master file
                importMod(importingMod2, grupTypes); //Import master file
    }

    private void execute() {
        //Found spell by edid
        Spell fireball = FinderByEdidFacade.create().findSpell("Fireball");
        //Select all existed NPC
        Collection<NPC> npcs = SelectorFacade.create().selectNPCs();
        //Get editing mod
        JSkyMod patch = ModManager.getInstance().getActiveMod();
        for (NPC npc : npcs) {
            //Add new spell to NPC
            npc.addSpell(fireball);
            //Put the changed NPC to mod
            patch.addMajor(npc);
        }
    }

    private void save() throws IOException, BadRecord {
        //Save created mod
        JSkyGlobal.getInstance().end();
    }

}
